package com.js.myapp.system.activity;

// Created by JS on 2021/6/9.

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.ViewTarget;
import com.bumptech.glide.request.transition.Transition;
import com.js.basicpage.activity.BaseLoadingDialogActivity;
import com.js.basicutils.NavigationBarUtil;
import com.js.basicutils.StatusBarUtil;
import com.js.myapp.R;
import com.js.myapp.common.centercrop.GlideBlurTransformation;
import com.js.myapp.databinding.ActivityBlurImageBinding;
/*使用Glide实现高斯模糊图片显示*/
public class BlurImageActivity extends BaseLoadingDialogActivity {

    private BlurImageActivity mContext;
    private ActivityBlurImageBinding binding;
    private String url1;
    private String url2;

    public static void start(Context context) {
        Intent intent = new Intent(context, BlurImageActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        binding = ActivityBlurImageBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        NavigationBarUtil.setSysNavigationColor(this, Color.parseColor("#141d26"));
        StatusBarUtil.setStatusBarColor(this, R.color.color_statusbar_bg);
        initData();
        initView();
    }

    private void initData() {
        url1 = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201607%2F31%2F20160731212731_PA8Zv.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625799998&t=87ee8f9e6d8bbe1675da12b5d0ebe6d9";
        url2 = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage14.m1905.cn%2Fuploadfile%2F2011%2F1024%2F20111024020532328.jpg&refer=http%3A%2F%2Fimage14.m1905.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625800102&t=6a304f0a974f12078a8262eea4e13d6a";

    }

    private void initView() {
        // 普通图片
        Glide.with(mContext).load(url1).into(binding.image1);
        // 高斯模糊图片
        Glide.with(mContext)
                .load(url2)
                .apply(RequestOptions.bitmapTransform(new GlideBlurTransformation(this, 5)))
                .into(new ViewTarget<ImageView, Drawable>(binding.image2) {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        Drawable current = resource.getCurrent();
                        binding.image2.setImageDrawable(current);
                    }
                });

        Glide.with(mContext).load(url2).into(binding.image3);
        Glide.with(mContext)
                .load(url2)
                .apply(RequestOptions.bitmapTransform(new GlideBlurTransformation(this, 5)))
                .into(new ViewTarget<RelativeLayout, Drawable>(binding.rlBackground) {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        Drawable current = resource.getCurrent();
                        binding.rlBackground.setBackground(current);
                    }
                });
    }
}
